<template>
  <div class="section_common">
    <div class="main">
      <el-form ref="form" label-width="100px">

        <el-form-item label="工号" required>
          <el-input v-model="jobNum" size="mini" readonly></el-input>
        </el-form-item>
        <el-form-item label="姓名" required>
          <el-input v-model="name" size="mini" readonly></el-input>
        </el-form-item>
        <el-form-item label="入职日期" required>
          <el-input v-model="entryDate" size="mini" readonly></el-input>
        </el-form-item>
        <el-form-item label="一级部门" required>
          <el-input v-model="onedept" size="mini" readonly></el-input>
        </el-form-item>
        <el-form-item label="二级部门" required>
          <el-input v-model="twodept" size="mini" readonly></el-input>
        </el-form-item>

        <el-form-item label="组别" required>
          <el-input v-model="sgroup" size="mini" readonly></el-input>
        </el-form-item>
        <el-form-item label="职位" required>
          <el-input v-model="posName" size="mini" readonly></el-input>
        </el-form-item>
        <el-form-item label="上班地点" required>
          <el-input v-model="workPlace" size="mini" readonly></el-input>
        </el-form-item>


        <van-dialog v-model="show" show-cancel-button :before-close="chargeBtn">
          <el-form-item label="驳回原因" required>
            <el-input v-model="reason" size="mini"></el-input>
          </el-form-item>
        </van-dialog>

        <el-form-item>
          <el-button id="isAgree" v-show="showtg" v-bind:disabled="isShow" type="primary" size="mini" @click="submitAgree">{{message}}</el-button>
          <el-button id="isNotAgree" v-show="showbh" v-bind:disabled="isShow" type="warning" size="mini" @click="submitNotAgree">{{message1}}</el-button>

        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  import Vue from 'vue';
  import {Toast,Picker,Popup,Dialog} from 'vant';
  Vue.use(Picker);
  Vue.use(Popup);
  Vue.use(Dialog)
export default {
  data() {
    return {
      title:"待转正管理",
      nowUser:"",
      id:"",

      jobNum:"",
      name:"",//部门名称
      onedept:"",
      twodept:"",//岗位名称
      sgroup:"",
      posName:"",
      workPlace:"",
      entryDate:"",
      reason:"",

      isShow:false,
      message:"通过",
      message1:"驳回",
      show:false,

      showtg:true,
      showbh:true,
    };
  },
  created() {
    this.nowUser=JSON.parse(localStorage.getItem('userInfo')).userId;
    this.id=this.$route.params.id;

    this.getDetail();//找到对应的页面详情
  },

  methods: {
//根据传递的招聘申请id获取相应的申请信息
    getDetail(){

      this.$https.post('/mobiles/selStayPositiveDetail', {
        nowUser:this.nowUser,
        id:this.id,
      }).then((res)=>{

        this.jobNum=res.data.data.jobNumId;
        this.name=res.data.data.name;
        this.onedept=res.data.data.onedeptName;
        this.twodept=res.data.data.twodeptName;
        this.sgroup=res.data.data.sgroup;
        this.posName=res.data.data.positionName;
        this.workPlace=res.data.data.workPlace;
        this.entryDate=res.data.data.entryDate;

        /*if (res.data.data.isAgree == "3"){
            this.message='已同意';
            this.isShow=true;
        }else if (res.data.data.isAgree == "1"){
            if (this.nowUser==res.data.data.leader){
                this.message='已同意';
                this.isShow=true;
            }
        }else if (res.data.data.isAgree == "2"){
            if (this.nowUser==res.data.data.hrleader || this.nowUser==res.data.data.leader){
                this.message='已同意';
                this.isShow=true;
            }
        }*/

        if (res.data.data.submit=='0'){
          this.isShow=true;
          this.message="已审核";
          this.showbh=false;
        }else if (res.data.data.submit=='1'){
          this.isShow=true;
          this.message="已通过";
          this.showbh=false;
        }else if (res.data.data.submit=='2'){
          this.isShow=true;
          this.message1="已驳回";
          this.showtg=false;
        }

      }).catch(err => {
        console.log(err);
      })
    },


    // 返回
    goBack() {
      this.$router.go(-1);
    },
    // 提交同意
    submitAgree() {
      this.$https.post('/mobiles/isAgreeStayPositive', {
        nowUser:this.nowUser,
        id:this.id,
      }).then(res => {
        res;
        Toast("已同意");
        this.message='已同意';
        this.isShow=true;
        this.getDetail();//找到对应的页面详情，及领导信息
        //JSON.parse(localStorage.getItem('userInfo')).userId;
        //this.$router.go(-1);

      }).catch(err => {
        console.log(err)
      });
    },

    //驳回
    submitNotAgree() {
      this.show=true;
    },
    chargeBtn(action,done){
      if (action==='cancel'){
        done();
      }else if (action==='confirm'){
        this.show=false;
        this.$https.post('/mobiles/isAgreeStayPositive', {
          nowUser:this.nowUser,
          id:this.id,
          reason:this.reason,
        }).then(res => {
          res;
          Toast("已驳回");
          this.getReceiveInfo();//找到对应的页面详情，及领导信息
        }).catch(err => {
          console.log(err)
        });
      }
    },

  },
};
</script>

<style lang="scss" scoped>
.main {
  display: flex;
  justify-items: center;
  margin: 0 auto;
  .el-form {
    padding-right: 10px;
    .el-form-item {
      .el-form-item__label {
        line-height: 16px;
      }
      margin-bottom: 5px;
    }
  }
}
</style>